﻿// =================================================================== 
// 项目说明
//====================================================================
// @Copy Right 2006-2008
// 文件： T_RECORD.cs
// 项目名称：Lovol 
// 创建时间：2011/9/19
// 负责人：
// ===================================================================
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Web;
using System.Web.UI;
using DP.Web;
using DP.Common;
using DP.Data.OracleClient;
using DP.Data.Common;

using CRM.Entity;
using System.Net;
using System.Xml;

namespace CRM.BLL
{
    /// <summary>
    /// 业务层实例类 SA.T_RECORD.
    /// </summary>
    public partial class T_RECORD_BLL
    {
        #region 成员
        ///<summary>
        /// 数据访问层 接口对象
        ///</summary>
        public readonly DAL<T_RECORD_Entity> _dal = DALFactory.CreateDal<T_RECORD_Entity>();
        /// <summary>
        /// 
        /// </summary>
        string xmlUrl;

        public string XmlUrl
        {
            get { return xmlUrl; }
            set { xmlUrl = value; }
        }
        string wfoUserName;

        public string WfoUserName
        {
            get { return wfoUserName; }
            set { wfoUserName = value; }
        }
        string wfoPassword;

        public string WfoPassword
        {
            get { return wfoPassword; }
            set { wfoPassword = value; }
        }
        UserLoginInfo _userLoginInfo;

        public UserLoginInfo UserLoginInfo
        {
            get { return _userLoginInfo; }
            set { _userLoginInfo = value; }
        }
        #endregion

        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary>
        public T_RECORD_BLL()
        {
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        public T_RECORD_BLL(UserLoginInfo _userLoginInfo, string xmlUrl, string wfoUserName, string wfoPassword)
        {
            this._userLoginInfo = _userLoginInfo;
            this.xmlUrl = xmlUrl;
            this.wfoUserName = wfoUserName;
            this.wfoPassword = wfoPassword;
        }
        #endregion

        #region 实例化函数

        #region 添加
        /// <summary>
        /// 向数据库中插入一条新记录。
        /// </summary>
        /// <param name="_T_RECORD_Entity">T_RECORD实体</param>
        /// <returns>影响的行数</returns>
        public long Insert(T_RECORD_Entity entity)
        {
            CacheHelper.ClearSession("T_RECORD_List");
            CacheHelper.ClearCache("T_RECORD_List");
            return _dal.Insert(entity);

        }
        #endregion

        #region 更新

        /// <summary>
        /// 向数据表T_RECORD更新一条记录。
        /// </summary>
        /// <param name="_T_RECORD_Entity">entity</param>
        /// <returns>影响的行数</returns>
        public int Update(T_RECORD_Entity entity)
        {
            CacheHelper.ClearSession("T_RECORD_List");
            CacheHelper.ClearCache("T_RECORD_List");
            return _dal.Update(entity);

        }
        /// <summary>
        /// 向数据表T_RECORD更新一条记录。
        /// </summary>
        /// <param name="_T_RECORD_Entity">entity</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>影响的行数</returns>
        public int Update(T_RECORD_Entity entity, StringBuilder partitionName)
        {
            CacheHelper.ClearSession("T_RECORD_List");
            CacheHelper.ClearCache("T_RECORD_List");
            return _dal.Update(entity, partitionName);

        }
        #endregion

        #region 删除
        /// <summary>
        /// 删除数据表T_RECORD中的一条记录
        /// </summary>
        /// <param name="AUTOID">AUTOID</param>
        /// <returns>影响的行数</returns>
        public int Delete(T_RECORD_Entity obj)
        {
            CacheHelper.ClearSession("T_RECORD_List");
            CacheHelper.ClearCache("T_RECORD_List");
            return _dal.Delete(obj);
        }

        /// <summary>
        /// 根据 指定字段 指定值 ,删除符合条件的。
        /// </summary>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <returns>影响行数</returns>
        public int Delete(string Conditions)
        {
            CacheHelper.ClearSession("T_RECORD_List");
            CacheHelper.ClearCache("T_RECORD_List");
            return _dal.Delete(Conditions);
        }

        /// <summary>
        /// 删除数据表的一表记录，根据 指定字段，指定值。
        /// </summary>
        /// <param name="Filed">字段</param>
        /// <param name="Value">值</param>
        /// <returns>影响行数</returns>
        public int Delete(string Field, string Value)
        {
            CacheHelper.ClearSession("T_RECORD_List");
            CacheHelper.ClearCache("T_RECORD_List");
            return _dal.Delete(Field, Value);

        }

        /// <summary>
        /// 删除数据表T_RECORD中的一条记录
        /// </summary>
        /// <param name="AUTOID">AUTOID</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>影响的行数</returns>
        public int Delete(T_RECORD_Entity obj, StringBuilder partitionName)
        {
            CacheHelper.ClearSession("T_RECORD_List");
            CacheHelper.ClearCache("T_RECORD_List");
            return _dal.Delete(obj, partitionName);
        }

        /// <summary>
        /// 根据 指定字段 指定值 ,删除符合条件的。
        /// </summary>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>影响行数</returns>
        public int Delete(string Conditions, StringBuilder partitionName)
        {
            CacheHelper.ClearSession("T_RECORD_List");
            CacheHelper.ClearCache("T_RECORD_List");
            return _dal.Delete(Conditions, partitionName);
        }

        /// <summary>
        /// 删除数据表的一表记录，根据 指定字段，指定值。
        /// </summary>
        /// <param name="Filed">字段</param>
        /// <param name="Value">值</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>影响行数</returns>
        public int Delete(string Field, string Value, StringBuilder partitionName)
        {
            CacheHelper.ClearSession("T_RECORD_List");
            CacheHelper.ClearCache("T_RECORD_List");
            return _dal.Delete(Field, Value, partitionName);

        }

        #endregion

        #region 根据 指定字段 指定值，返回单个实体类
        /// <summary>
        /// 根据 指定字段 指定值 ,返回一个T_RECORD对象
        /// </summary>
        /// <param name="Field">字段名</param>
        /// <param name="Value">字段值</param>
        /// <returns>T_RECORD_Entity 对象</returns>
        public T_RECORD_Entity GetEntity(string Field, string Value)
        {
            return _dal.GetEntity(Field, Value);
        }
        /// <summary>
        /// 根据 指定字段 指定值 ,返回一个T_RECORD对象
        /// </summary>
        /// <param name="Field">字段名</param>
        /// <param name="Value">字段值</param>
        /// <returns>T_RECORD_Entity 对象</returns>
        public T_RECORD_Entity GetEntity(string Field, int Value)
        {
            return _dal.GetEntity(Field, Value.ToString());
        }
        /// <summary>
        /// 根据 指定字段 指定值 ,返回一个T_RECORD对象
        /// </summary>
        /// <param name="Field">字段名</param>
        /// <param name="Value">字段值</param>
        /// <returns>T_RECORD_Entity 对象</returns>
        public T_RECORD_Entity GetEntity(string Field, long Value)
        {
            return _dal.GetEntity(Field, Value.ToString());
        }

        /// <summary>
        /// 根据 指定字段 指定值 ,返回一个T_RECORD对象
        /// </summary>
        /// <param name="Field">字段名</param>
        /// <param name="Value">字段值</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>T_RECORD_Entity 对象</returns>
        public T_RECORD_Entity GetEntity(string Field, string Value, StringBuilder partitionName)
        {
            return _dal.GetEntity(Field, Value, partitionName);
        }
        /// <summary>
        /// 根据 指定字段 指定值 ,返回一个T_RECORD对象
        /// </summary>
        /// <param name="Field">字段名</param>
        /// <param name="Value">字段值</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>T_RECORD_Entity 对象</returns>
        public T_RECORD_Entity GetEntity(string Field, int Value, StringBuilder partitionName)
        {
            return _dal.GetEntity(Field, Value.ToString(), partitionName);
        }
        /// <summary>
        /// 根据 指定字段 指定值 ,返回一个T_RECORD对象
        /// </summary>
        /// <param name="Field">字段名</param>
        /// <param name="Value">字段值</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>T_RECORD_Entity 对象</returns>
        public T_RECORD_Entity GetEntity(string Field, long Value, StringBuilder partitionName)
        {
            return _dal.GetEntity(Field, Value.ToString(), partitionName);
        }
        #endregion

        #region 返回实体类集合
        /// <summary>
        /// 得到数据表T_RECORD所有记录
        /// </summary>		
        /// <remarks>
        /// 示例:
        /// List＜T_RECORD_Entity＞ list = T_RECORD_DAL.Get_T_RECORD_List();
        /// </remarks>
        /// <returns>List＜T_RECORD_Entity＞对象集</returns>
        public List<T_RECORD_Entity> GetList()
        {
            return _dal.GetList();
        }
        /// <summary>
        /// 得到符合条件的，数据表T_RECORD所有记录
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// List＜T_RECORD_Entity＞ list = T_RECORD_DAL.Get_T_RECORD_List(" and 1=1 ");
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <returns>List＜T_RECORD_Entity＞对象集</returns>
        public List<T_RECORD_Entity> GetList(string Conditions)
        {
            return _dal.GetList(Conditions);
        }
        /// <summary>
        /// 得到符合条件的，数据表T_RECORD所有记录
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// List＜T_RECORD_Entity＞ list = T_RECORD_DAL.Get_T_RECORD_List(" and 1=1 ");
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="Sort">排序字段</param>
        /// <returns>List＜T_RECORD_Entity＞对象集</returns>
        public List<T_RECORD_Entity> GetList(string Conditions, string Sort)
        {
            return _dal.GetList(Conditions, Sort);
        }
        /// <summary>
        /// 得到符合条件的，数据表T_RECORD所有记录
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// List＜T_RECORD_Entity＞ list = T_RECORD_DAL.Get_T_RECORD_List(" and 1=1 ", 0, 10);
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="StartRecordIndex">记录开始</param>
        /// <param name="PageSize">页大小</param>
        /// <returns>List＜T_RECORD_Entity＞对象集</returns>
        public List<T_RECORD_Entity> GetList(string Conditions, int StartRecordIndex, int PageSize)
        {
            return _dal.GetList(Conditions, StartRecordIndex, PageSize);
        }
        /// <summary>
        /// 得到符合条件的，数据表T_RECORD所有记录
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// IList＜T_RECORD_Entity＞ list = T_RECORD_DAL.Get_T_RECORD_List(" and 1=1 ", 0, 10, "ID");
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="StartRecordIndex">记录开始</param>
        /// <param name="PageSize">页大小</param>
        /// <param name="Sort">排序字段</param>
        /// <returns>IList＜T_RECORD_Entity＞对象集</returns>
        public List<T_RECORD_Entity> GetList(string Conditions, int StartRecordIndex, int PageSize, string Sort)
        {
            return _dal.GetList(Conditions, StartRecordIndex, PageSize, Sort);
        }

        /// <summary>
        /// 得到数据表T_RECORD所有记录
        /// </summary>		
        /// <remarks>
        /// 示例:
        /// List＜T_RECORD_Entity＞ list = T_RECORD_DAL.Get_T_RECORD_List();
        /// </remarks>
        /// <param name="partitionName">分区表名</param>
        /// <returns>List＜T_RECORD_Entity＞对象集</returns>
        public List<T_RECORD_Entity> GetList(StringBuilder partitionName)
        {
            return _dal.GetList(partitionName);
        }
        /// <summary>
        /// 得到符合条件的，数据表T_RECORD所有记录
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// List＜T_RECORD_Entity＞ list = T_RECORD_DAL.Get_T_RECORD_List(" and 1=1 ");
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>List＜T_RECORD_Entity＞对象集</returns>
        public List<T_RECORD_Entity> GetList(string Conditions, StringBuilder partitionName)
        {
            return _dal.GetList(Conditions, partitionName);
        }
        /// <summary>
        /// 得到符合条件的，数据表T_RECORD所有记录
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// List＜T_RECORD_Entity＞ list = T_RECORD_DAL.Get_T_RECORD_List(" and 1=1 ");
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="Sort">排序字段</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>List＜T_RECORD_Entity＞对象集</returns>
        public List<T_RECORD_Entity> GetList(string Conditions, string Sort, StringBuilder partitionName)
        {
            return _dal.GetList(Conditions, Sort, partitionName);
        }
        /// <summary>
        /// 得到符合条件的，数据表T_RECORD所有记录
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// List＜T_RECORD_Entity＞ list = T_RECORD_DAL.Get_T_RECORD_List(" and 1=1 ", 0, 10);
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="StartRecordIndex">记录开始</param>
        /// <param name="PageSize">页大小</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>List＜T_RECORD_Entity＞对象集</returns>
        public List<T_RECORD_Entity> GetList(string Conditions, int StartRecordIndex, int PageSize, StringBuilder partitionName)
        {
            return _dal.GetList(Conditions, StartRecordIndex, PageSize, partitionName);
        }
        /// <summary>
        /// 得到符合条件的，数据表T_RECORD所有记录
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// IList＜T_RECORD_Entity＞ list = T_RECORD_DAL.Get_T_RECORD_List(" and 1=1 ", 0, 10, "ID");
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="StartRecordIndex">记录开始</param>
        /// <param name="PageSize">页大小</param>
        /// <param name="Sort">排序字段</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>IList＜T_RECORD_Entity＞对象集</returns>
        public List<T_RECORD_Entity> GetList(string Conditions, int StartRecordIndex, int PageSize, string Sort, StringBuilder partitionName)
        {
            return _dal.GetList(Conditions, StartRecordIndex, PageSize, Sort, partitionName);
        }
        #endregion

        #region 返回DataSet 对象
        /// <summary>
        /// 得到数据表T_RECORD所有记录
        /// </summary>		
        /// <remarks>
        /// 示例:
        /// DataTable table = T_RECORD_DAL.GetDataTable();
        /// </remarks>
        /// <returns>DataSet集</returns>
        public DataTable GetDataTable()
        {
            return _dal.GetDataTable();
        }
        /// <summary>
        /// 得到符合条件的，数据表T_RECORD所有记录
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// DataTable table = T_RECORD_DAL.GetDataTable(" and 1=1 ");
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <returns>List< T_RECORD_Entity> 对象集</returns>
        public DataTable GetDataTable(string Conditions)
        {
            return _dal.GetDataTable(Conditions);
        }
        /// <summary>
        /// 得到符合条件的，数据表T_RECORD所有记录
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// DataTable table = T_RECORD_DAL.GetDataTable(" and 1=1 ");
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="Sort">排序字段</param>
        /// <returns>List< T_RECORD_Entity> 对象集</returns>
        public DataTable GetDataTable(string Conditions, string Sort)
        {
            return _dal.GetDataTable(Conditions, Sort);
        }
        /// <summary>
        /// 得到符合条件的，数据表T_RECORD所有记录
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// DataTable table = T_RECORD_DAL.GetDataTable(" and 1=1 ", 0, 10);
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="StartRecordIndex">记录开始</param>
        /// <param name="PageSize">页大小</param>
        /// <returns>List< T_RECORD_Entity> 对象集</returns>
        public DataTable GetDataTable(string Conditions, int StartRecordIndex, int PageSize)
        {
            return _dal.GetDataTable(Conditions, StartRecordIndex, PageSize);
        }
        /// <summary>
        /// 得到符合条件的，数据表T_RECORD所有记录
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// DataTable table = T_RECORD_DAL.GetDataTable(" and 1=1 ", 0, 10);
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="StartRecordIndex">记录开始</param>
        /// <param name="PageSize">页大小</param>
        /// <param name="Sort">排序字段</param>
        /// <returns>List< T_RECORD_Entity> 对象集</returns>
        public DataTable GetDataTable(string Conditions, int StartRecordIndex, int PageSize, string Sort)
        {
            return _dal.GetDataTable(Conditions, StartRecordIndex, PageSize, Sort);
        }

        /// <summary>
        /// 得到数据表T_RECORD所有记录
        /// </summary>		
        /// <remarks>
        /// 示例:
        /// DataTable table = T_RECORD_DAL.GetDataTable();
        /// </remarks>
        /// <param name="partitionName">分区表名</param>
        /// <returns>DataSet集</returns>
        public DataTable GetDataTable(StringBuilder partitionName)
        {
            return _dal.GetDataTable(partitionName);
        }
        /// <summary>
        /// 得到符合条件的，数据表T_RECORD所有记录
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// DataTable table = T_RECORD_DAL.GetDataTable(" and 1=1 ");
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>List< T_RECORD_Entity> 对象集</returns>
        public DataTable GetDataTable(string Conditions, StringBuilder partitionName)
        {
            return _dal.GetDataTable(Conditions, partitionName);
        }
        /// <summary>
        /// 得到符合条件的，数据表T_RECORD所有记录
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// DataTable table = T_RECORD_DAL.GetDataTable(" and 1=1 ");
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="Sort">排序字段</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>List< T_RECORD_Entity> 对象集</returns>
        public DataTable GetDataTable(string Conditions, string Sort, StringBuilder partitionName)
        {
            return _dal.GetDataTable(Conditions, Sort, partitionName);
        }
        /// <summary>
        /// 得到符合条件的，数据表T_RECORD所有记录
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// DataTable table = T_RECORD_DAL.GetDataTable(" and 1=1 ", 0, 10);
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="StartRecordIndex">记录开始</param>
        /// <param name="PageSize">页大小</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>List< T_RECORD_Entity> 对象集</returns>
        public DataTable GetDataTable(string Conditions, int StartRecordIndex, int PageSize, StringBuilder partitionName)
        {
            return _dal.GetDataTable(Conditions, StartRecordIndex, PageSize, partitionName);
        }
        /// <summary>
        /// 得到符合条件的，数据表T_RECORD所有记录
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// DataTable table = T_RECORD_DAL.GetDataTable(" and 1=1 ", 0, 10);
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="StartRecordIndex">记录开始</param>
        /// <param name="PageSize">页大小</param>
        /// <param name="Sort">排序字段</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>List< T_RECORD_Entity> 对象集</returns>
        public DataTable GetDataTable(string Conditions, int StartRecordIndex, int PageSize, string Sort, StringBuilder partitionName)
        {
            return _dal.GetDataTable(Conditions, StartRecordIndex, PageSize, Sort, partitionName);
        }
        #endregion

        #region 查询实体总数
        /// <summary>
        /// 查询实体数
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// int val = T_RECORD_DAL.GetCount();
        /// </remarks>
        /// <returns>实体的总数</returns>
        public long GetCount()
        {
            return _dal.GetCount();
        }

        /// <summary>
        /// 查询符合条件的实体总数
        /// </summary>		
        /// <remarks>
        /// 示例:
        /// int val = T_RECORD_DAL.GetCount(" and 1=1 ");
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <returns>实体的总数</returns>
        public long GetCount(string Conditions)
        {
            return _dal.GetCount(Conditions);
        }

        /// <summary>
        /// 查询实体数
        /// </summary>	
        /// <remarks>
        /// 示例:
        /// int val = T_RECORD_DAL.GetCount();
        /// </remarks>
        /// <param name="partitionName">分区表名</param>
        /// <returns>实体的总数</returns>
        public long GetCount(StringBuilder partitionName)
        {
            return _dal.GetCount(partitionName);
        }

        /// <summary>
        /// 查询符合条件的实体总数
        /// </summary>		
        /// <remarks>
        /// 示例:
        /// int val = T_RECORD_DAL.GetCount(" and 1=1 ");
        /// </remarks>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>实体的总数</returns>
        public long GetCount(string Conditions, StringBuilder partitionName)
        {
            return _dal.GetCount(Conditions, partitionName);
        }
        #endregion

        #region 检测是否存在
        /// <summary>
        /// 检测记录是否存在
        /// </summary>
        /// <param name="Field"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public int IsExist(string Field, string Value)
        {
            return _dal.IsExist(Field, Value);
        }
        /// <summary>
        /// 检测记录是否存在
        /// </summary>
        /// <param name="Field"></param>
        /// <param name="Value"></param>
        /// <param name="partitionName">分区表名</param>
        /// <returns></returns>
        public int IsExist(string Field, string Value, StringBuilder partitionName)
        {
            return _dal.IsExist(Field, Value, partitionName);
        }
        #endregion

        #region 获取 指定字段的 最大值
        /// <summary>
        /// 获取 指定字段的 返回 最大值
        /// </summary>
        /// <param name="Field">字段名</param>
        /// <returns>最大值</returns>		
        public string GetMaxValue(string Field)
        {
            return _dal.GetMaxValue(Field);
        }
        /// <summary>
        /// 获取 指定字段的 返回 最大值
        /// </summary>
        /// <param name="Field">字段名</param>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <returns>最大值</returns>		
        public string GetMaxValue(string Field, string Conditions)
        {
            return _dal.GetMaxValue(Field, Conditions);
        }

        /// <summary>
        /// 获取 指定字段的 返回 最大值
        /// </summary>
        /// <param name="Field">字段名</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>最大值</returns>		
        public string GetMaxValue(string Field, StringBuilder partitionName)
        {
            return _dal.GetMaxValue(Field, partitionName);
        }
        /// <summary>
        /// 获取 指定字段的 返回 最大值
        /// </summary>
        /// <param name="Field">字段名</param>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>最大值</returns>		
        public string GetMaxValue(string Field, string Conditions, StringBuilder partitionName)
        {
            return _dal.GetMaxValue(Field, Conditions, partitionName);
        }
        #endregion

        #region 获取 指定字段的 最小值
        /// <summary>
        /// 获取 指定字段的 返回 最小值
        /// </summary>
        /// <param name="Field">字段名</param>
        /// <returns>最小值</returns>		
        public string GetMinValue(string Field)
        {
            return _dal.GetMinValue(Field);
        }
        /// <summary>
        /// 获取 指定字段的 返回 最小值
        /// </summary>
        /// <param name="Field">字段名</param>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <returns>最小值</returns>		
        public string GetMinValue(string Field, string Conditions)
        {
            return _dal.GetMinValue(Field, Conditions);
        }

        /// <summary>
        /// 获取 指定字段的 返回 最小值
        /// </summary>
        /// <param name="Field">字段名</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>最小值</returns>		
        public string GetMinValue(string Field, StringBuilder partitionName)
        {
            return _dal.GetMinValue(Field, partitionName);
        }
        /// <summary>
        /// 获取 指定字段的 返回 最小值
        /// </summary>
        /// <param name="Field">字段名</param>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>最小值</returns>		
        public string GetMinValue(string Field, string Conditions, StringBuilder partitionName)
        {
            return _dal.GetMinValue(Field, Conditions, partitionName);
        }
        #endregion

        #region 获取 指定字段的  唯一行
        /// <summary>
        /// 获取 指定字段的 返回 唯一行
        /// </summary>
        /// <param name="Fields">字段名 多个字段 用"," 分隔 </param>
        /// <returns>结果集中的唯一行</returns>
        public DataTable GetDistinctTable(string Fields)
        {
            return _dal.GetDistinctTable(Fields);
        }
        /// <summary>
        /// 获取 指定字段的 返回 唯一行
        /// </summary>
        /// <param name="Fields">字段名 多个字段 用"," 分隔 </param>
        /// <returns>结果集中的唯一行</returns>
        public DataTable GetDistinctTable(string Fields, string Conditions)
        {
            return _dal.GetDistinctTable(Fields, Conditions);
        }

        /// <summary>
        /// 获取 指定字段的 返回 唯一行
        /// </summary>
        /// <param name="Fields">字段名 多个字段 用"," 分隔 </param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>结果集中的唯一行</returns>
        public DataTable GetDistinctTable(string Fields, StringBuilder partitionName)
        {
            return _dal.GetDistinctTable(Fields, partitionName);
        }
        /// <summary>
        /// 获取 指定字段的 返回 唯一行
        /// </summary>
        /// <param name="Fields">字段名 多个字段 用"," 分隔 </param>
        /// <param name="Conditions">Where条件，不需写“Where”</param>
        /// <param name="partitionName">分区表名</param>
        /// <returns>结果集中的唯一行</returns>
        public DataTable GetDistinctTable(string Fields, string Conditions, StringBuilder partitionName)
        {
            return _dal.GetDistinctTable(Fields, Conditions, partitionName);
        }
        #endregion

        #region 检测表是否存在
        /// <summary>
        /// 根据表名 检测表是否存在 （精确查询）
        /// </summary>
        /// <param name="TableName">表名</param>
        /// <returns>是/否</returns>
        public bool IsExistTable()
        {
            return _dal.IsExistTable();
        }

        /// <summary>
        /// 根据表名 查询符合条件的 表信息 （模糊查询） 
        /// </summary>
        /// <param name="TableName">表名</param>
        /// <returns></returns>
        public DataTable GetTableList(string TableName)
        {
            return _dal.GetTableList(TableName);
        }

        #endregion


        #region 检测字段是否存在
        /// <summary>
        /// 根据字段名 检测字段是否存在 （精确查询）
        /// </summary>
        /// <param name="FieldName">字段名</param>
        /// <returns>是/否</returns>
        public bool IsExistField(string FieldName)
        {
            return _dal.IsExistField(FieldName);
        }

        /// <summary>
        /// 根据字段名 查询符合条件的 字段信息 （模糊查询） 
        /// </summary>
        /// <param name="FieldName">字段名</param>
        /// <returns></returns>
        public DataTable GetFieldList(string FieldName)
        {
            return _dal.GetFieldList(FieldName);
        }

        #endregion

        #region 缓存
        #region Session
        /// <summary>
        /// 得到数据表T_RECORD所有缓存记录
        /// 缓存 会 缓存 表的全部数据到 程序内存中。对于记录 量大的表请勿使用些方法。
        /// </summary>
        /// <param name="page">当前页面对象</param>
        ///<returns></returns>
        public List<T_RECORD_Entity> GetSession_T_RECORD_List(Page page)
        {
            List<T_RECORD_Entity> list = CacheHelper.GetSession("T_RECORD_List") as List<T_RECORD_Entity>;
            if (list == null)
            {
                list = _dal.GetList("") as List<T_RECORD_Entity>;
                CacheHelper.SetSession("T_RECORD_List", list);
            }
            return list;
        }
        /// <summary>
        /// 根据主键 ID ,查询缓存返回一个T_RECORD对象
        /// 缓存 会 缓存 表的全部数据到 程序内存中。对于记录 量大的表请勿使用些方法。
        /// </summary>
        /// <param name="page">当前页面对象</param>
        /// <param name="aUTOID">aUTOID</param>
        /// <returns>T_RECORD_Entity 对象</returns>
        public T_RECORD_Entity GetSession_T_RECORD_EntityByKey(Page page, int aUTOID)
        {
            List<T_RECORD_Entity> list = GetSession_T_RECORD_List(page);
            T_RECORD_Entity entity = list.Find(delegate(T_RECORD_Entity en) { if (en.AUTOID == aUTOID) return true; else return false; });

            return entity;
        }

        #endregion

        #region PageItem
        /// <summary>
        /// 得到数据表T_RECORD所有缓存记录
        /// 缓存 会 缓存 表的全部数据到 程序内存中。对于记录 量大的表请勿使用些方法。
        /// </summary>
        /// <param name="page">当前页面对象</param>
        ///<returns></returns>
        public List<T_RECORD_Entity> GetPageItem_T_RECORD_List(Page page)
        {
            List<T_RECORD_Entity> list = CacheHelper.GetPageItem(page, "T_RECORD_List") as List<T_RECORD_Entity>;
            if (list == null)
            {
                list = _dal.GetList("") as List<T_RECORD_Entity>;
                CacheHelper.SetPageItem(page, "T_RECORD_List", list);
            }
            return list;
        }
        /// <summary>
        /// 根据主键 ID ,查询缓存返回一个T_RECORD对象
        /// 缓存 会 缓存 表的全部数据到 程序内存中。对于记录 量大的表请勿使用些方法。
        /// </summary>
        /// <param name="page">当前页面对象</param>
        /// <param name="aUTOID">aUTOID</param>
        /// <returns>T_RECORD_Entity 对象</returns>
        public T_RECORD_Entity GetPageItem_T_RECORD_EntityByKey(Page page, int aUTOID)
        {
            List<T_RECORD_Entity> list = GetPageItem_T_RECORD_List(page);
            T_RECORD_Entity entity = list.Find(delegate(T_RECORD_Entity en) { if (en.AUTOID == aUTOID) return true; else return false; });

            return entity;
        }

        #endregion

        #region Cache
        /// <summary>
        /// 得到数据表T_RECORD所有缓存记录
        /// 缓存 会 缓存 表的全部数据到 程序内存中。对于记录 量大的表请勿使用些方法。
        /// </summary>
        /// <param name="page">当前页面对象</param>
        ///<returns></returns>
        public List<T_RECORD_Entity> GetCache_T_RECORD_List(Page page)
        {
            List<T_RECORD_Entity> list = CacheHelper.GetCache("T_RECORD_List") as List<T_RECORD_Entity>;
            if (list == null)
            {
                list = _dal.GetList("") as List<T_RECORD_Entity>;
                CacheHelper.SetCache("T_RECORD_List", list);
            }
            return list;
        }
        /// <summary>
        /// 根据主键 ID ,查询缓存返回一个T_RECORD对象
        /// 缓存 会 缓存 表的全部数据到 程序内存中。对于记录 量大的表请勿使用些方法。
        /// </summary>
        /// <param name="page">当前页面对象</param>
        /// <param name="aUTOID">aUTOID</param>
        /// <returns>T_RECORD_Entity 对象</returns>
        public T_RECORD_Entity GetCache_T_RECORD_EntityByKey(Page page, int aUTOID)
        {
            List<T_RECORD_Entity> list = GetCache_T_RECORD_List(page);
            T_RECORD_Entity entity = list.Find(delegate(T_RECORD_Entity en) { if (en.AUTOID == aUTOID) return true; else return false; });

            return entity;
        }

        #endregion
        #endregion

        #endregion

        #region 自定义实例化函数

        /// <summary>
        /// 从WFO 跟据 ucid 获取 录音信息
        /// Gets the remote info.
        /// </summary>
        /// <param name="ucid">The ucid.</param>
        /// <returns></returns>
        public T_RECORD_Entity GetRemoteInfo(string ucid)
        {
            T_RECORD_Entity recordEntity = new T_RECORD_Entity();
            recordEntity.CALLID = ucid;
            if (String.IsNullOrEmpty(ucid))
            {
                return recordEntity;
            }
            try
            {
                Page page = HttpContext.Current.Handler as Page;
                T_CONFIG_BLL configBll = new T_CONFIG_BLL();
                String xmlUrl = configBll.GetCacheValueByName(page, "WFOSearch");
                string wfoUserName = configBll.GetCacheValueByName(page, "WFOUserName");
                string wfoPassword = configBll.GetCacheValueByName(page, "WFOPassword");

                #region 获取
                string url = String.Format(xmlUrl, ucid);
                NetworkCredential networkCredential = new NetworkCredential(wfoUserName, wfoPassword);

                XmlUrlResolver resolver = new XmlUrlResolver();
                resolver.Credentials = networkCredential;

                XmlReaderSettings mySettings = new XmlReaderSettings();
                mySettings.ProhibitDtd = false;
                mySettings.ValidationType = ValidationType.DTD;
                mySettings.XmlResolver = resolver;


                XmlReader myRead = XmlReader.Create(url, mySettings);
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(myRead);

                XmlNodeList xmlNodeList = xmlDocument.GetElementsByTagName("result");
                foreach (XmlNode xmlNode in xmlNodeList)
                {
                    recordEntity.INUM = xmlNode.Attributes["inum"].Value;
                }

                xmlNodeList = xmlDocument.GetElementsByTagName("field");
                foreach (XmlNode xmlNode in xmlNodeList)
                {
                    switch (xmlNode.Attributes["name"].Value)
                    {
                        case "startedat":
                            {
                                recordEntity.STARTDATE = DateTimeHelper.ToDateTime(xmlNode.InnerText.Replace("T", " "));
                            }
                            break;
                        case "duration":
                            {
                                recordEntity.DURATION = StringHelper.ToInt(xmlNode.InnerText);
                            }
                            break;
                        case "partynames":
                            {
                                recordEntity.PARTYNAMES = xmlNode.InnerText;
                            }
                            break;
                        case "callid":
                            {
                                //recordEntity.CALLID = xmlNode.InnerText;
                            }
                            break;

                    }
                } 
                #endregion
            }
            catch(Exception ex)
            {
                LogHelper.WriteLog("Log_WFO", String.Format("UCID:{1}--{0}", ex.Message, ucid));
            }

            return recordEntity;
        }

        /// <summary>
        /// 从WFO 跟据 ucid 获取 录音信息
        /// Gets the remote info.
        /// </summary>
        /// <param name="ucid">The ucid.</param>
        /// <param name="xmlUrl">The XML URL.</param>
        /// <param name="wfoUserName">Name of the wfo user.</param>
        /// <param name="wfoPassword">The wfo password.</param>
        /// <returns></returns>
        public T_RECORD_Entity GetRemoteInfo(string ucid, string xmlUrl, string wfoUserName, string wfoPassword)
        {
            T_RECORD_Entity recordEntity = new T_RECORD_Entity();
            recordEntity.CALLID = ucid;
            if (String.IsNullOrEmpty(ucid))
            {
                return recordEntity;
            }
            try
            {
                #region 获取
                string url = String.Format(xmlUrl, ucid);
                NetworkCredential networkCredential = new NetworkCredential(wfoUserName, wfoPassword);

                XmlUrlResolver resolver = new XmlUrlResolver();
                resolver.Credentials = networkCredential;

                XmlReaderSettings mySettings = new XmlReaderSettings();
                mySettings.ProhibitDtd = false;
                mySettings.ValidationType = ValidationType.DTD;
                mySettings.XmlResolver = resolver;


                XmlReader myRead = XmlReader.Create(url, mySettings);
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(myRead);

                List<RecordResult> list = new List<RecordResult>();


                XmlNodeList xmlSubNodeList;
                XmlNodeList xmlNodeList = xmlDocument.GetElementsByTagName("result");
                foreach (XmlNode xmlNode in xmlNodeList)
                {
                    RecordResult entity = new RecordResult();
                    entity.inum = xmlNode.Attributes["inum"].Value;
                    xmlSubNodeList = xmlNode.ChildNodes;
                    foreach (XmlNode xmlSubNode in xmlSubNodeList)
                    {
                        switch (xmlSubNode.Attributes["name"].Value)
                        {
                            case "startedat":
                                {
                                    entity.startedat = DateTimeHelper.ToDateTime(xmlSubNode.InnerText.Replace("T", " "));
                                }
                                break;
                            case "duration":
                                {
                                    entity.duration = StringHelper.ToInt(xmlSubNode.InnerText);
                                }
                                break;
                            case "partynames":
                                {
                                    entity.partynames = xmlSubNode.InnerText;
                                }
                                break;
                            case "callid":
                                {
                                    entity.callid = xmlSubNode.InnerText;
                                }
                                break;
                            case "partyagentnames":
                                {
                                    entity.partyagentnames = xmlSubNode.InnerText;
                                }
                                break;
                            case "vdn":
                                {
                                    entity.vdn = xmlSubNode.InnerText;
                                }
                                break;

                        }
                    }
                    list.Add(entity);
                }
                
                if (list.Count > 0)
                {
                    list.Sort((x, y) => x.inum.CompareTo(y.inum));
                    RecordResult recordResult = list[list.Count - 1];
                    recordEntity.INUM = recordResult.inum;
                    recordEntity.PARTYNAMES = recordResult.partynames;
                    recordEntity.STARTDATE = recordResult.startedat;
                    recordEntity.DURATION = recordResult.duration;
                }

                #endregion
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("Log_WFO", String.Format("UCID:{1}--{0}", ex.Message, ucid));
            }

            return recordEntity;
        }

        /// <summary>
        /// Downloads the file.
        /// </summary>
        /// <param name="inum">The inum.</param>
        /// <param name="filePath">The file path.</param>
        /// <returns></returns>
        public bool DownloadFile(string inum, string filePath)
        {
            bool rel = false;
            Page page = HttpContext.Current.Handler as Page;
            T_CONFIG_BLL configBll = new T_CONFIG_BLL();
            WebClient myClient = new WebClient();

            String xmlUrl = configBll.GetCacheValueByName(page, "WFOReplay");
            string wfoUserName = configBll.GetCacheValueByName(page, "WFOUserName");
            string wfoPassword = configBll.GetCacheValueByName(page, "WFOPassword");
            NetworkCredential networkCredential = new NetworkCredential(wfoUserName, wfoPassword);
            myClient.Credentials = networkCredential;
            string url = String.Format(xmlUrl, inum);

            myClient.Encoding = System.Text.Encoding.Default;

            try
            {
                myClient.DownloadFile(url, filePath);
                rel = true;
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("Log_Record_DownloadFile", String.Format("INUM:{1}--{0}", ex.Message, inum));
                rel = false;
            }
            return rel;
        }

        /// <summary>
        /// Repairs the case record write.
        /// </summary>
        /// <param name="obj">The obj.</param>
        public void RepairCaseRecordWrite(object obj)
        {
            T_REPAIRCASE_Entity repairCaseEntity = obj as T_REPAIRCASE_Entity;
            //LogHelper.WriteLog("Log_WFO", String.Format("xmlUrl:{0}", this.xmlUrl));
            //LogHelper.WriteLog("Log_WFO", String.Format("wfoUserName:{0}", this.wfoUserName));
            //LogHelper.WriteLog("Log_WFO", String.Format("wfoPassword:{0}", this.wfoPassword));
            if (repairCaseEntity == null)
            {
                return;
            }
            try
            {
                //LogHelper.WriteLog("Log_WFO", String.Format("CALLID:{0}", repairCaseEntity.CALLID));
                T_RECORD_Entity recordEntity = GetRemoteInfo(repairCaseEntity.CALLID, this.xmlUrl, this.wfoUserName, this.wfoPassword);

                //LogHelper.WriteLog("Log_WFO", String.Format("INUM:{0}", recordEntity.INUM));
                recordEntity.CALLTYPE = repairCaseEntity.CALLTYPE;
                recordEntity.CASEID = repairCaseEntity.CASEID;
                recordEntity.CALLER = repairCaseEntity.CALLER;
                recordEntity.CALLED = repairCaseEntity.CALLED;
                recordEntity.CASETYPE = (int)WorkOrderType.报修工单;
                //LogHelper.WriteLog("Log_WFO", String.Format("USERNAME:{0}", _userLoginInfo.UserEntity.USERNAME));

                recordEntity.CREATEPEOPLE = _userLoginInfo.UserEntity.USERNAME;
                recordEntity.CREATEPEOPLEID = _userLoginInfo.UserEntity.USERID;
                recordEntity.CREATETIME = DateTime.Now;
                recordEntity.BUSINESSDIVISIONCODE = _userLoginInfo.UserEntity.BUSINESSDIVISIONCODE;
                recordEntity.BUSINESSDIVISIONID = _userLoginInfo.UserEntity.BUSINESSDIVISIONID;
                recordEntity.BUSINESSDIVISIONNAME = _userLoginInfo.UserEntity.BUSINESSDIVISIONNAME;
                _dal.Insert(recordEntity);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("Log_WFO", String.Format("ExceptionMessage:{0}", ex.Message));
            }
        }


        /// <summary>
        /// Repairs the case record write.
        /// </summary>
        /// <param name="obj">The obj.</param>
        public void ComplaintCaseRecordWrite(object obj)
        {
            T_COMPLAINTCASE_Entity complaintCaseEntity = obj as T_COMPLAINTCASE_Entity;
            //LogHelper.WriteLog("Log_WFO", String.Format("xmlUrl:{0}", this.xmlUrl));
            //LogHelper.WriteLog("Log_WFO", String.Format("wfoUserName:{0}", this.wfoUserName));
            //LogHelper.WriteLog("Log_WFO", String.Format("wfoPassword:{0}", this.wfoPassword));
            if (complaintCaseEntity == null)
            {
                return;
            }
            try
            {
                //LogHelper.WriteLog("Log_WFO", String.Format("CALLID:{0}", repairCaseEntity.CALLID));
                T_RECORD_Entity recordEntity = GetRemoteInfo(complaintCaseEntity.CALLID, this.xmlUrl, this.wfoUserName, this.wfoPassword);

                //LogHelper.WriteLog("Log_WFO", String.Format("INUM:{0}", recordEntity.INUM));
                recordEntity.CALLTYPE = complaintCaseEntity.CALLTYPE;
                recordEntity.CASEID = complaintCaseEntity.CASEID;
                recordEntity.CALLER = complaintCaseEntity.CALLER;
                recordEntity.CALLED = complaintCaseEntity.CALLED;
                recordEntity.CASETYPE = (int)WorkOrderType.投诉工单;
                //LogHelper.WriteLog("Log_WFO", String.Format("USERNAME:{0}", _userLoginInfo.UserEntity.USERNAME));

                recordEntity.CREATEPEOPLE = _userLoginInfo.UserEntity.USERNAME;
                recordEntity.CREATEPEOPLEID = _userLoginInfo.UserEntity.USERID;
                recordEntity.CREATETIME = DateTime.Now;
                recordEntity.BUSINESSDIVISIONCODE = _userLoginInfo.UserEntity.BUSINESSDIVISIONCODE;
                recordEntity.BUSINESSDIVISIONID = _userLoginInfo.UserEntity.BUSINESSDIVISIONID;
                recordEntity.BUSINESSDIVISIONNAME = _userLoginInfo.UserEntity.BUSINESSDIVISIONNAME;
                _dal.Insert(recordEntity);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("Log_WFO", String.Format("ExceptionMessage:{0}", ex.Message));
            }
        }


        /// <summary>
        /// Repairs the case record write.
        /// </summary>
        /// <param name="obj">The obj.</param>
        public void ConsultingCaseRecordWrite(object obj)
        {
            T_CONSULTINGCASE_Entity consultingCaseEntity = obj as T_CONSULTINGCASE_Entity;
            //LogHelper.WriteLog("Log_WFO", String.Format("xmlUrl:{0}", this.xmlUrl));
            //LogHelper.WriteLog("Log_WFO", String.Format("wfoUserName:{0}", this.wfoUserName));
            //LogHelper.WriteLog("Log_WFO", String.Format("wfoPassword:{0}", this.wfoPassword));
            if (consultingCaseEntity == null)
            {
                return;
            }
            try
            {
                //LogHelper.WriteLog("Log_WFO", String.Format("CALLID:{0}", consultingCaseEntity.CALLID));
                T_RECORD_Entity recordEntity = GetRemoteInfo(consultingCaseEntity.CALLID, this.xmlUrl, this.wfoUserName, this.wfoPassword);

                //LogHelper.WriteLog("Log_WFO", String.Format("INUM:{0}", recordEntity.INUM));
                recordEntity.CALLTYPE = consultingCaseEntity.CALLTYPE;
                recordEntity.CASEID = consultingCaseEntity.CASEID;
                recordEntity.CALLER = consultingCaseEntity.CALLER;
                recordEntity.CALLED = consultingCaseEntity.CALLED;
                recordEntity.CASETYPE = (int)WorkOrderType.咨询工单;
                //LogHelper.WriteLog("Log_WFO", String.Format("USERNAME:{0}", _userLoginInfo.UserEntity.USERNAME));

                recordEntity.CREATEPEOPLE = _userLoginInfo.UserEntity.USERNAME;
                recordEntity.CREATEPEOPLEID = _userLoginInfo.UserEntity.USERID;
                recordEntity.CREATETIME = DateTime.Now;
                recordEntity.BUSINESSDIVISIONCODE = _userLoginInfo.UserEntity.BUSINESSDIVISIONCODE;
                recordEntity.BUSINESSDIVISIONID = _userLoginInfo.UserEntity.BUSINESSDIVISIONID;
                recordEntity.BUSINESSDIVISIONNAME = _userLoginInfo.UserEntity.BUSINESSDIVISIONNAME;
                _dal.Insert(recordEntity);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("Log_WFO", String.Format("ExceptionMessage:{0}", ex.Message));
            }
        }


        #endregion

        public class RecordResult
        {
            public string inum { get; set; }
            public DateTime? startedat { get; set; }
            public int? duration { get; set; }
            public string partyagentnames { get; set; }
            public string partynames { get; set; }
            public string vdn { get; set; }
            public string callid { get; set; }
        }
    }
}
